# Contributor: Fernando Casas Schossow <casasfernando@outlook.com>
# Maintainer: Fernando Casas Schossow <casasfernando@outlook.com>
pkgname=ocaml-libvirt
_pkgname=libvirt-ocaml
pkgver=0.6.1.7
pkgrel=0
pkgdesc="OCaml binding for libvirt"
url="https://libvirt.org/ocaml/"
arch="all !riscv64 !loongarch64" # ocaml
license="LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception"
makedepends="autoconf automake ocaml ocaml-findlib-dev libvirt-dev perl gawk"
subpackages="$pkgname-dev $pkgname-doc"
source="https://gitlab.com/libvirt/libvirt-ocaml/-/archive/v$pkgver/libvirt-ocaml-v$pkgver.tar.gz"
options="!check" # there is no test suite/unit tests
builddir="$srcdir/$_pkgname-v$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

prepare() {
	default_prepare
	autoreconf -i
}

build() {
	./configure \
		--host=$CHOST \
		--build=$CBUILD \
		--target=$CTARGET \
		--prefix=/usr
	make
}

package() {
	export DESTDIR="$pkgdir"
	export OCAMLFIND_DESTDIR="$DESTDIR/usr/lib/ocaml"
	mkdir -p "$OCAMLFIND_DESTDIR" "$OCAMLFIND_DESTDIR/stublibs"

	make install
	install -Dm644 COPYING COPYING.LIB \
		-t "$pkgdir"/usr/share/licenses/$pkgname/
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
065008709b653f52e119665a5fbe4bedeb1dceb430b2d3ce022d4f9d685e168860145d40f6ae2be4d0715da5c0815029c9de49d370c73cd54d0e83846dc6a785  libvirt-ocaml-v0.6.1.7.tar.gz
"
